package com.sky.controller.admin;


import com.sky.constant.StatusConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

import java.nio.charset.StandardCharsets;


@RestController("adminShopController")
@Slf4j
@RequestMapping("/admin/shop")
@Api(tags = "店铺操作接口")
@RequiredArgsConstructor
public class ShopController {

    public static  final String KEY="SHOP_STATUS";
    private final RedisTemplate redisTemplate;
    @ApiOperation("获取店铺的营业状态")
    @GetMapping("/status")
    public Result<Integer> getBusinessStatus(){
        ValueOperations valueOperations = redisTemplate.opsForValue();
        Integer status = (Integer) valueOperations.get(KEY);
        log.info("获取店铺的营业状态:{}",status==1? StatusConstant.ENABLE:StatusConstant.DISABLE);

        return Result.success(status);
    }

    @ApiOperation("设置店铺的营业状态")
    @PutMapping("/{status}")
    public Result setBusinessStatus(@PathVariable Integer status){
        ValueOperations valueOperations = redisTemplate.opsForValue();
        log.info("设置店铺的营业状态:{}",status==1? StatusConstant.ENABLE:StatusConstant.DISABLE);
        valueOperations.set(KEY, status);
        return Result.success();
    }
}
